package com.wlz.utils;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 * @author wlz
 * @date 2023-06-13  20:52
 */
public class PatternTest {

    public static String filterCharacters(String message) {
        String allowedCharacters = "[A-Za-z0-9\n\r /?()\\-+:.,']";
        Pattern pattern = Pattern.compile(allowedCharacters);
        Matcher matcher = pattern.matcher(message);
        StringBuilder filteredMessage = new StringBuilder();

        while (matcher.find()) {
            filteredMessage.append(matcher.group());
            System.out.println(filteredMessage);
        }

        return filteredMessage.toString();
    }

    public static void main(String[] args) {
        String message = "Hello! 张文良 大幅 防守打法大法师大法师大萨达 This is a test message. Filter out unwanted characters: #&*@^";

        String filteredMessage = filterCharacters(message);
        System.out.println("----------------");
        System.out.println(filteredMessage);
    }
}
